<template>
	<view class="content">
		<view class="hot-view" style="margin-top: 50rpx;">
			<view class="hot-item" v-for="(item, index) in hotData" :key="item.index">
				<view class="icon-bg" :class="index%2==0 ? '' : 'icon-bg2'" @click="getHotContent(item)">
					<image class="icon" :src="iconBgs[index]"></image>
				</view>
				<text class="name">{{item.name}}</text>
			</view>
		</view>
		<view class="title-bar">
			<text class="title">我的题库</text>
		</view>
		<view class="hot-view">
			<view class="hot-item" v-for="(item, index) in myData" :key="index" @click="getMineContent(item.name)">
				<view class="icon-bg" :class="index%2==0 ? '' : 'icon-bg2'">
					<image class="icon" :src="myIcons[index]"></image>
				</view>
				<text class="name">{{item.name}}</text>
			</view>
		</view>
	</view>
</template>

<script>
	import MockData from '@/mockdata/mockdata.js'
	import Config from '@/config/config.js'
	import {
		parseObj
	} from '@/common/util.js'
	export default {
		data() {
			return {
				title: '首页',
				background: ['color1', 'color2', 'color3'],
				iconBgs: ['/static/flash.png', '/static/ios-folder-outline.png', '/static/paper.png',
					'/static/today.png', '/static/icon-bulb.png', '/static/ios-ribbon.png'
				],
				myIcons: ['/static/heart.png', '/static/ios-list-box.png', '/static/bug.png', '/static/book.png'],
				indicatorDots: true,
				autoplay: true,
				interval: 2000,
				duration: 500,
				dataSource: null,
				hotData: [{
					index: 0,
					name: '全部练习'
				}, {
					index: 1,
					name: '随机练习'
				}, {
					index: 2,
					name: '模拟考试'
				}],
				myData: [{
					index: 0,
					name: '试题收藏'
				}, {
					index: 1,
					name: '错题库'
				}],
				curCourse: {}
			}
		},
		onLoad() {
			// this.initData();
			this.load();
		},
		methods: {
			initData() {
				try {
					let token = uni.getStorageSync('token');
					let course = uni.getStorageSync('course');
					if (token) {
						getApp().globalData.token = token;
					}
					if (course) {
						course = JSON.parse(course);
						this.curCourse = course;
						getApp().globalData.course = course;
						getApp().globalData.professionId = course.professionId;
						getApp().globalData.courseId = course.courseId || course.id;
					} else {
						uni.navigateTo({
							url: '/pages/index/category'
						})
					}
				} catch (e) {
					// error
				}
			},
			load() {
				let params = {
					professionId: getApp().globalData.professionId,
					courseId: getApp().globalData.courseId
				};
			},
			changeIndicatorDots(e) {
				this.indicatorDots = !this.indicatorDots
			},
			changeAutoplay(e) {
				this.autoplay = !this.autoplay
			},
			intervalChange(e) {
				this.interval = e.target.value
			},
			durationChange(e) {
				this.duration = e.target.value
			},
			getImgUrl(img) {
				return Config.baseUrl + img;
			},
			getHotContent(data) {
				setTimeout(() => {
					uni.navigateTo({
						url: '/pages/index/timu?index=' + data.index + '&name=' + data.name
					});
				}, 10);
			},
			getMineContent(type) {
				console.log(type)
				switch (type) {
					case '试题收藏':
						uni.navigateTo({
							url: '/pages/index/mycollect'
						});
						break;
					case '错题库':
						uni.navigateTo({
							url: '/pages/index/subject'
						});
						break;
					default:
						break;
				}
			},
			getWrongTimuList(data) {
				uni.navigateTo({
					url: '/pages/index/wrongtimu'
				});
			},
			// 切换专业
			showSwitchModal() {
				uni.navigateTo({
					url: '/pages/index/category'
				})
			},
			goLogin() {
				uni.navigateTo({
					url: '/pages/account/login'
				});
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		background-color: #f8f8f8;
	}

	.header {
		height: 50rpx;
		justify-content: center;
		align-items: center;
		padding-bottom: 10rpx;
	}

	.header-title {
		font-size: 34rpx;
		color: #333333;
		font-weight: 400;
		height: 50rpx;
		line-height: 50rpx;
		align-self: center;
		text-align: center;
	}

	.uni-margin-wrap {
		width: 690rpx;
		margin: 0 30rpx;
	}

	.swiper {
		height: 300rpx;
	}

	.swiper-item {
		display: block;
		height: 300rpx;
		line-height: 300rpx;
		text-align: center;
	}

	.swiper-image {
		width: 100%;
		height: 300rpx;
	}

	.hot-view {
		display: flex;
		width: 100%;
		background-color: white;
		flex-direction: row;
		flex-wrap: wrap;
	}

	.hot-item {
		flex-direction: column;
		width: 33%;
		height: 150rpx;
		left: 10%;
		margin-top: 10rpx;
		margin-bottom: 5rpx;
		justify-content: center;
		align-items: center;
		position: relative;
	}

	.icon-bg {
		display: flex;
		background-color: #41c364;
		width: 100rpx;
		height: 100rpx;
		border-radius: 100rpx;
		justify-content: center;
		align-items: center;
	}

	.icon-bg2 {
		background-color: #ed675a;
	}

	.icon {
		width: 50rpx;
		height: 50rpx;
	}

	.name {
		font-size: 30rpx;
		margin-top: 10rpx;
		width: 33%;
		text-align: center;
	}

	.title-bar {
		display: flex;
		width: 100%;
		height: 50rpx;
		align-items: center;
		background-color: white;
		margin-top: 10rpx;
		padding: 10rpx;
		font-weight: bold;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
		padding-left: 40rpx;
		height: 30rpx;
		line-height: 30rpx;
		text-align: left;
		position: relative;
	}
</style>